﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-3 control-label ">服务项目<font class="red"> *</font></label>
            <div class="col-sm-4">
                <div id="productId" col="ProductId"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">设备类型<font class="red"> *</font></label>
            <div class="col-sm-4">
                <div id="deviceName" col="DeviceName"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">是否必须</label>
            <div class="col-sm-4" id="isMustDevice" col="IsMustDevice"></div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        getForm();

        $('#form').validate({
            rules: {
                productId: { required: true },
                deviceName: { required: true }
            }
        });

        $("#productId").ysComboBox({
            url: '@Url.Content("~/ProductManage/Product/GetListJson")',
            key: "Id",
            value: "ProductName",
            class: "form-control"
        });

        $("#deviceName").ysComboBox({
            url: '@Url.Content("~/DeviceManage/Device/GetListJson")',
            key: "Field1",
            value: "Field1",
            class: "form-control"
        });

        $("#isMustDevice").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(IsEnum).EnumToDictionaryString())) });
    });

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/ProductManage/ProductDevice/GetFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        $('#form').setWebControls(obj.Result);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            if (!postData.ProductId) {
                alert("请选择服务项目");
                return;
            }
            if (!postData.DeviceName) {
                alert("请选择设备类型");
                return;
            }
            ys.ajax({
                url: '@Url.Content("~/ProductManage/ProductDevice/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

